package com.example.shipback.controller;

import com.example.shipback.utils.WebSocketUtils;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.net.URISyntaxException;

/**
 * @author emil
 */
@RequestMapping("/client/websocket")
@RestController
@CrossOrigin
@Slf4j
public class WebSocketController {
    private static final Logger logger = LoggerFactory.getLogger(WebSocketController.class);

    @PostMapping("/sendMessage")
    public void sendMessage(@RequestBody String message) throws URISyntaxException, InterruptedException {
        String url = "ws://localhost:8094/ws";
        logger.info("sendMessage: {}", message);
        WebSocketUtils.sendMessage(url, message);
    }
}
